/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * Author     : 王海斌
 * E-mail     : wanghaibin@qiyi.com
 * Version    :
 * Date       : Fri 07 Dec 2018 12:53:01 PM CST
 * Destription:
 *
 */
#include <sys/time.h>
#include <iostream>

#include "speedinfo.h"

SpeedInfo::SpeedInfo()
: start_(0)
, end_(0)
, dnsTime_(0)
, connTime_(0)
, firstDataTime_(0)
, firstByteTime_(0)
, finDataTime_(0)
, dataLen_(0)
{
}

SpeedInfo::~SpeedInfo()
{
}

void SpeedInfo::Start()
{
    start_ = GetNowUs();
}

void SpeedInfo::End()
{
    end_ = GetNowUs();
}

void SpeedInfo::FinishDNS()
{
    dnsTime_ = GetNowUs();
}

void SpeedInfo::FinishConnect()
{
    connTime_ = GetNowUs();
}

void SpeedInfo::FinishData()
{
    finDataTime_ = GetNowUs();
}

void SpeedInfo::FinishFirstByte()
{
    firstByteTime_ = GetNowUs();
}

void SpeedInfo::FinishFirstData()
{
    firstDataTime_ = GetNowUs();
}

long long SpeedInfo::GetNowUs()
{
    struct timeval now;
    gettimeofday(&now, NULL);
    return ((long long) now.tv_sec * 1000 + (long long) now.tv_usec / 1000);
}

void SpeedInfo::SetReadCount(long long len)
{
    dataLen_ = len;
}

